Skip to content

Shape Drawing Improvements#116

Open
SoloByte wants to merge 305 commits intomainfrom
circle-poly-improved-outline-drawing
Open

Shape Drawing Improvements#116
SoloByte wants to merge 305 commits intomainfrom
circle-poly-improved-outline-drawing

Conversation

@SoloByte
Copy link
Copy Markdown
Collaborator

@SoloByte SoloByte commented Dec 10, 2025

Summary

This PR is about overhauling, cleaning, and improving Shape drawing in ShapeEngine. The main goal is to fix all outline drawing functions of closed shapes and Polyline drawing.
I am implementing custom algorithms to construct and draw triangles instead of just drawing lines with cap types. Currently, using colors with any transparency for outlines will look bad on almost all shapes (line, ray, segment are not affected). Every other shape will have overlaps in the corners that will become visible with alpha values below 255.

Current Problematic Version

ShapeEngine-ShapeOutlineDrawingProblem

New Version

ShapeEngine-ShapeOutlineDrawing-New

ShapeEngine-ShapeOutlineDrawing-New2

Affected Functions

Below is a list of functions that are affected by this problem and need to be fixed (might be missing some functions):

  • CircleLine
  • CircleSectorLine
  • CircleLinePercentage
  • RingLine
  • RingSectorLine
  • TriangleLine
  • TrianglePercentageLine
  • TriangleCornered
  • TriangleRounded
  • TriangleRoundedLines
  • RectLines
  • RectRounded
  • RectRoundedLines
  • RectPercentageLines
  • RectCornered
  • RectSlantedCorners
  • QuadLines
  • QuadRounded
  • QuadRoundedLines
  • QuadPercentageLines
  • QuadCornered
  • QuadSlantedCorners
  • PolygonLines
  • PolygonCornered
  • PolygonPercentageLines
  • PolygonRoundedLines
  • PolygonRounded
  • Polyline
  • PolylineRounded
  • PolylinePercentage
  • PolylineCornered
  • Check performance of old versions vs new versions (If old versions are significantly faster, I might have to add them back in with a *Fast prefix with the caveat of only being able to draw fully opaque colors)

At first, I did not realize how much work it would be to do this, and I just started working on this. Thankfully, I am close to the end now with most of the functions already working. Still needs complete testing to make sure all of this works!

Performance

This should (theoretically) come with performance improvements on a lot of drawing functions because they are now drawing much fewer triangles than before. The downside is that the function itself needs to do more work to calculate all the triangle points needed.

I have made some preliminary (quick) testing and so far the new functions are 50% to 400% faster than the old ones. The new functions basically always draw the minimal number of triangles needed to display the shape outline, whereas the old functions (depending on the corner points used) drew a lot of overlapping triangles in the corners. Drawing triangles and draw calls are the most expensive, so the much fewer draw calls outweigh the extra computations needed in the new functions.

In some cases I left the old functions intact because they provide a benefit/feature (end caps for instance) that the new functions do not have. The limitation I have added is that all old functions that are left set the alpha of the provided color to 255 (no transparency) now.

I will test it once I am finished. The new ones will stay no matter what because they can be used with transparent colors but I might have to add all (or a selection) of old draw functions for faster performance.

…ved. Percentage drawing now uses quad percentage drawing.

Refactor: QuadDrawing cleaned up and simplified (percentage drawing needs still to be overhauled)
Refactor: Rect DrawRounded removed. Draw now has parameters for drawing rounded.
Feat: DrawRoundedCornerFractionHelper finished.
Refactor: DrawQuadLinesPercentageHelper improvements.
Fix: DrawRoundedCornerHelper works correctly again.
…l corner instead of a half corner to prevent drawing incorrect corner segments.
Refactor: Some clean up.
SoloByte added 30 commits March 18, 2026 11:23
Refactor: Small fixes
Todo: Todos added
Refactor: Certain Functions reimplemented in ClipperImmediate2D from ShapeClipper.
Refactor: Circle cleanup.
Fix: OutlineDrawingExample updated.
Feat: Segments new functions added.
Todo: PolylineMath.cs & PolygonMath.cs todos added.
Refactor: Triangulation cleanup.
Refactor: Rng cleanup.
Refactor: ShapeList new result based functions added.
Refactor: Circle and CircleMath clean up.
…shapes.

Refactor: ProjectShape in all shapes fixed based on new ConvexHull system.
Feat: New functions with result parameters added.
Docs: Some docs updated / added.
Feat: GenerateFractureLine overload with result parameter added.
….cs. (Polygon overrides some of them)

Docs: Missing xml summaries added to functions.
Refactor: CutWithRay function moved to PolygonMath.cs
Refactor: Polyline GetInterpolatedEdgePoints functions overhauled.
…er overloads added.

Docs: Missing xml summaries added.
Docs: added missing xml summaries and fixed old xml summaries.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Improvement of existing code.

Projects

Status: Active

Development

Successfully merging this pull request may close these issues.

1 participant